/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package comandaXM.utils.format;



import javax.swing.JTable;
import comandaXM.excepcions.ExceptionXML;  

/**
 *
 * @author xmarti
 */
public class FormatJTable {
    private FormatJSplitPane data;    
    private JTable jTable;
    private String path;

    public FormatJTable(){
        
    }
    public FormatJTable(JTable jTable, String path) throws ExceptionXML  {        
        Format format= new Format();            
        this.jTable=jTable;
        this.path=path;            
        this.data= new FormatJSplitPane();
        try {
            this.data= format.read (path+".XML");
        } catch (ExceptionXML ex) {
            this.setFormat();
            this.saveFormat();
        }        
    }

    public void chargeFormat(){
         for (int i =0; i< this.data.getCols().size();i++){
            jTable.getColumnModel().getColumn(i).setPreferredWidth(data.getCol(i));                                                   
         } 

    }
    public void setFormat(){              
       this.data.resetCols();
       for (int i =0; i< jTable.getColumnModel().getColumnCount();i++){
            this.data.setCol(jTable.getColumnModel().getColumn(i).getWidth());           
       }
       
    }
    public void saveFormat() throws ExceptionXML {
        Format format= new Format();         
        format.write(path+".XML", this.data);        
    }    
}
